package com.fesnakj.todos.jpa;

import org.hsqldb.server.Server;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.PrintWriter;


public class DataBase2 implements ServletContextListener {

    private static Server dbServer;
    public static void startDB() {
        dbServer = new Server();
        dbServer.setAddress("localhost");
        dbServer.setDatabaseName(0, "cerber");
        dbServer.setDatabasePath(0, "file:C:\\UBS\\Dev\\projects\\todo\\db\\cerber");
        dbServer.setPort(1234);
        dbServer.setTrace(true);
        dbServer.setLogWriter(new PrintWriter(System.out));
        dbServer.start();
    }

    public static void closeDB() {
        dbServer.stop();
        dbServer.shutdown();
    }

    public static void main(String[] args) throws InterruptedException {
        startDB();
    }


    public void contextInitialized(ServletContextEvent servletContextEvent) {
        startDB();
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        closeDB();
    }

}